package com.fmdj.nebula.controller;

import com.fmdj.common.util.CommonResult;
import com.fmdj.nebula.controller.form.CalculateOrderMileageForm;
import com.fmdj.nebula.controller.form.InsertOrderGpsForm;
import com.fmdj.nebula.controller.form.SearchOrderGpsForm;
import com.fmdj.nebula.controller.form.SearchOrderLastGpsForm;
import com.fmdj.nebula.controller.vo.InsertOrderGpsVo;
import com.fmdj.nebula.service.OrderGpsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.HashMap;

@RestController
@RequestMapping("/order/gps")
@Tag(name = "OrderGpsController", description = "订单GPS服务web接口")
@Slf4j
public class OrderGpsController {

    @Autowired
    private OrderGpsService orderGpsService;

    @PostMapping("/insertOrderGps")
    @Operation(summary = "插入订单Gps记录")
    public CommonResult insertOrderGps(@RequestBody @Valid InsertOrderGpsForm form) {
        int rows = orderGpsService.insertOrderGps(form.getList());
        return CommonResult.ok().put(CommonResult.RETURN_ROW, rows);
    }

    @PostMapping("/searchOrderGps")
    @Operation(summary = "查询某个订单的所有GPS定位")
    public CommonResult searchOrderGps(@RequestBody @Valid SearchOrderGpsForm form) {
        ArrayList<HashMap> list = orderGpsService.searchOrderGps(form.getOrderId());
        return CommonResult.ok().put(CommonResult.RETURN_RESULT, list);
    }

    @PostMapping("/searchOrderLastGps")
    @Operation(summary = "查询某个订单的最后一条GPS定位")
    public CommonResult searchOrderLastGps(@RequestBody @Valid SearchOrderLastGpsForm form) {
        HashMap hashMap = orderGpsService.searchOrderLastGps(form.getOrderId());
        return CommonResult.ok().put(CommonResult.RETURN_RESULT, hashMap);
    }

    @PostMapping("/calculateOrderMileage")
    @Operation(summary = "计算订单里程")
    public CommonResult calculateOrderMileage(@RequestBody @Valid CalculateOrderMileageForm form) {
        String mileage = orderGpsService.calculateOrderMileage(form.getOrderId());
        return CommonResult.ok().put(CommonResult.RETURN_RESULT, mileage);
    }

}
